package com.ssamkj.rssbot.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RemoveSpecialChar {
	public enum TYPE{
		NO_NEW_LINE(0);
		private int type;
		TYPE(int type){
			this.type = type;
		}
		public int getType(){
			return this.type;
		}
	}
	private static final String removePattern = "&#39;|&nbsp;|&lsquo;|&rsquo;|&lsquo|&quot;|&lt;|&gt;|&amp;";
	private static final String replacePattern = "\n\n";
	public synchronized String removeSpecialChar(String input1){
		String input = new String(input1);
		
		Pattern p;
		Matcher m;
		p = Pattern.compile(removePattern);
		m = p.matcher(input);
		if(m.find()){
			input = m.replaceAll("");
		}
		
		p = Pattern.compile(replacePattern);
		m = p.matcher(input);
		if(m.find()){
			input = m.replaceAll("\n");
		}
		return input;
	}

	public synchronized String removeSpecialChar(String input1, TYPE type) {
		String input = new String(input1);
		Pattern p;
		Matcher m;
		p = Pattern.compile(removePattern);
		m = p.matcher(input);
		if(m.find()){
			input = m.replaceAll("");
		}
		p = Pattern.compile(replacePattern);
		m = p.matcher(input);
		if(m.find()){
			if(type.equals(TYPE.NO_NEW_LINE)){
				input = m.replaceAll("");
			}else{
				input = m.replaceAll("\n");	
			}
		}
		return input;
	}
}
